package org.example.hospital_frontend.controller;

import org.example.hospital_frontend.common.Result;
import org.example.hospital_frontend.domain.MedicalRecordTemplate;
import org.example.hospital_frontend.service.MedicalRecordTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/medical/templates")
public class MedicalRecordTemplateController {
    
    @Autowired
    private MedicalRecordTemplateService templateService;
    
    // 获取所有模板
    @GetMapping("/list")
    public Result getTemplateList() {
        return Result.success(templateService.list());
    }
    
    // 根据ID获取模板
    @GetMapping("/{id}")
    public Result getTemplate(@PathVariable Integer id) {
        return Result.success(templateService.getById(id));
    }
    
    // 添加模板
    @PostMapping("/add")
    public Result addTemplate(@RequestBody MedicalRecordTemplate template) {
        templateService.save(template);
        return Result.success();
    }
    
    // 更新模板
    @PostMapping("/update")
    public Result updateTemplate(@RequestBody MedicalRecordTemplate template) {
        templateService.update(template);
        return Result.success();
    }
    
    // 删除模板
    @DeleteMapping("/{id}")
    public Result deleteTemplate(@PathVariable Integer id) {
        templateService.removeById(id);
        return Result.success();
    }
} 